package com.aha.firstchapter.first;

import java.util.Scanner;

/**
 * 桶排序
 * Created by wangxin on 2015/10/27.
 */
public class BucketSort {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] arr = {5,3,1,4,7,6,9,2,8,8};
        BucketSort bs = new BucketSort();
        bs.start(arr);
    }
    public void start(int[] arr){
        int[] book = new int[10];
        for (int i = 0; i < book.length; i++) {
            book[i] = 0;
        }
        for (int j = 0; j < arr.length; j++) {
            book[arr[j]]++;
        }
        //输出 从小到大
        for (int n = 0; n < arr.length; n++) {
            for (int m = 0; m < book[n]; m++) {
                System.out.print(n+" ");
            }
        }
        System.out.println("");
        //输出 从大到小
        for (int n = arr.length-1; n > 0; n--) {
            for (int m = 0; m < book[n]; m++) {
                System.out.print(n+" ");
            }
        }
        System.out.println("");
        //次数
        for (int p = 0; p < book.length; p++) {
            System.out.println(p+"出现的次数"+book[p]);
        }
    }
}
